package com.tcredit.sdk.android;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;


/**
 * Created by Administrator on 2018/6/10.
 */

public class StringUtils {

    /**
     * 本地图片转换成base64字符串
     * @param imgFile 图片本地路径
     */
    public static String ImageToBase64ByLocal(String imgFile) {// 将图片文件转化为字节数组字符串，并对其进行Base64编码处理
        InputStream in = null;
        byte[] data = null;

        // 读取图片字节数组
        try {
            in = new FileInputStream(imgFile);

            data = new byte[in.available()];
            in.read(data);

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (in == null) {
                try {
                    in.close();
                } catch (Exception e) {
                }
            }
        }
        // 对字节数组Base64编码
        Base64 encoder = new Base64();
        return encoder.encode(data);// 返回Base64编码过的字节数组字符串
    }


}
